<template>
    <div class="parbox">
        <div class="box1">
            <basic-form
                :showAlert="false"
                message="请先填写基本信息提交保存后，再上传证照扫描图片"
                :isBtn="false"
                :formInfos="s_FormInfo"
                :formDatas="s_formDatas"
                :rules="s_rules"
                ref="forms"
                @onSubmit="onSubmit"
                @onChangeType="onChangeType"
            ></basic-form>
        </div>
        <div class="box2">
            <a-button class="btn"  type="primary"  @click="nexts()">
                下一步
            </a-button>
        </div>
    </div>
</template>

<script>
import basicForm from '../common/basicForm'
import {saveInfo } from './purchaseOrder'
const s_FormInfo = [
  { label: '采购类型', name: 'purType', type: 'dicselect',dicName: 'purType',  placeholder: '请选择采购类型' },
  // { label: '采购单号', name: 'purOrderNo', type: 'input', placeholder: '请输入采购单号' },
  // { label: '无税总价', name: 'totalIunitprice', type: 'input', placeholder: '请输入无税总价' },
  // { label: '含税总价', name: 'totalPrice', type: 'input', placeholder: '请输入含税总价',scopedSlots: { customRender: 'tofixed2' }  },
  { label: '送货类型', name: 'deliveryType', type: 'dicselect',dicName: 'deliveryType',  placeholder: '请选择送货类型' },
  { label: '收货地址', name: 'deliveryAddr', type: 'deliveryAddressSelect', placeholder: '请选择地址' },
  // { label: '收货人及电话', name: 'consignee', type: 'input', placeholder: '请输入收货人及电话' },
  { label: '收货人', name: 'delivery', type: 'input', placeholder: '请输入收货人' },
  { label: '收货人电话', name: 'deliveryTel', type: 'input', placeholder: '请输入收货人电话' },
  { label: '结算方式', name: 'settlementType', type: 'dicselect',dicName: 'settlementType',  placeholder: '请选择结算方式' },
  // { label: '配送状态', name: 'deliveryState', type: 'dicselect',dicName: 'deliveryState',  placeholder: '请选择配送状态' },
  // { label: '开票状态', name: 'invoiceState', type: 'dicselect',dicName: 'invoiceState',  placeholder: '请选择开票状态' },
  // { label: '订单状态', name: 'purOrderState', type: 'dicselect',dicName: 'purOrderState',  placeholder: '请选择订单状态' },
  { label: '采购单位备注', name: 'remarks', type: 'textarea', placeholder: '请输入采购单位备注' },
  { label: ['保存', '重置'], type: 'botton' },
]
const s_formDatas = {
  sysSeq: 0,
  pid: '',
  purType: null,
  purOrderNo:null,
  totalIunitprice: null,
  totalPrice: null,
  deliveryType: null,
  deliveryAddr: null,
  delivery:null,
  deliveryTel:null,
  consignee: null,
  deliveryState: null,
  invoiceState: null,
  purOrderState: null,
  settlementType:null,
  remarks: null,
}
const s_rules = {
  purType: [{ required: true, message: '采购类型必填', trigger: 'blur' }],
  deliveryAddr: [{ required: true, message: '收货地址必填', trigger: 'blur' }],
}
export default {
  props: {
  },
  components: {
    basicForm,
  },
  data() {
    return {
     s_FormInfo:s_FormInfo,
      s_formDatas: s_formDatas,
      s_rules: s_rules,
      isSubmit:false
    }
  },
  created(){

  },
  mounted() {
    console.log("000000000");
    this.s_formDatas = {
        sysSeq: 0,
        pid: '',
        purType: null,
        purOrderNo:null,
        totalIunitprice: null,
        totalPrice: null,
        deliveryType: null,
        deliveryAddr: null,
        delivery:null,
        deliveryTel:null,
        consignee: null,
        deliveryState: null,
        invoiceState: null,
        purOrderState: null,
        settlementType:null,
        remarks: null,
    }
  },
  methods: {
    nexts(){
        this.$refs.forms.submitForm()
    },
    onSubmit(val) {
      // if(this.isSubmit){
      //     this.$emit('nextStep')
      // }else{
        this.saveObjInfo(val)
      // }
      
    },
    // 保存详细信息
    async saveObjInfo(val) {
      // this.$message.loading({ content: '提交中'， })
      let res = await saveInfo(val)
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        this.$message.success({ content: '保存成功', duration: 2 })
        this.isSubmit=true;
        Object.assign(this.s_formDatas,res.data)
        this.$emit('nextStep',res.data)
      } else {
        this.$message.error({ content: '保存失败', duration: 2 })
      }
    },
    // 搜索栏选择下拉select触发搜索val[0]表示选中的record中的pid,val[1]表示选中的record全部信息
    onChangeType(name, val) {
      console.log('formName',name)
      console.log('val',val)
      this.s_formDatas=this.$refs.forms.form
      switch (name) {
        case 'deliveryAddr': 
          if (!val[0]) {
            this.s_formDatas.deliveryAddr =null
            this.s_formDatas.delivery=null
            this.s_formDatas.deliveryTel=null
 
          }else{
            this.s_formDatas.deliveryAddr =val[1].addr
            this.s_formDatas.delivery =val[1].contact
            this.s_formDatas.deliveryTel =val[1].contactTel
          }
          break 
      }
    },
  },
}
</script>

<style scoped>
.stepBox{
    width: 100%;
    height: 100%;
    position: relative;
}
.cont{
  padding-left: 5px;
  max-height:calc( 70vh - 40px );
  overflow-y: scroll;
}
.btnBox{
  height: 7vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items:flex-end;
  /* border: 1px solid #eee; */
  position: absolute;
  bottom: 0px;
}

</style>


